package com.csw;

import java.sql.*;

public class mysqlTest {
    public static void main(String[] args) throws Exception{
        //1.加载这个包  加载第三方工具
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接 root passwd url
        String url="jdbc:mysql://master:3306/csw";
        String username="root";
        String passwd="123456";
        Connection connection = DriverManager.getConnection(url, username, passwd);
        //3.获取执行器
        Statement statement = connection.createStatement();
        String sql="select * from student";
        ResultSet rs = statement.executeQuery(sql);

        //4.获取结果并解析
        while(rs.next()){
            String name = rs.getString("name");
            System.out.println(name);
        }
        //关闭连接
        rs.close();
        statement.close();
        connection.close();
    }
}
